Add async waitFor() helper for DOM-based detections#227
Open
Add async waitFor() helper for DOM-based detections#227
waitFor() helper for DOM-based detections#227Conversation
Implement the wait() async helper function that waits for a detection to return true by repeatedly checking it on each animation frame. This is useful for DOM-based detections that need to wait for elements to appear before the document is fully loaded. - Add wait() function that loops using requestAnimationFrame - Add comprehensive tests for the wait function - Update test infrastructure to support async detection functions - Add JSDoc documentation with usage examples Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add elementReady-like helper for DOM detections
Add async Jan 24, 2026
wait() helper for DOM-based detections
fregante
reviewed
Jan 24, 2026
index.ts
Outdated
| * } | ||
| * ``` | ||
| */ | ||
| export async function wait(detection: () => boolean): Promise<boolean> { |
Member
There was a problem hiding this comment.
- Export via
utilsonly. - Revert type changes (
detectionFn = detect as) in index.test.ts - Rename to
waitFor
Contributor
Author
There was a problem hiding this comment.
Done in commit b177e73:
- Renamed
waittowaitFor - Moved to
utilsexport only (removed direct export) - Reverted type assertion changes in index.test.ts
- Renamed wait() to waitFor() as requested - Moved export to utils object instead of direct export - Reverted type assertion changes in index.test.ts - Updated README to show usage via utils.waitFor() - Updated JSDoc example to reflect new API Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot
AI
changed the title
Add async
Add async Jan 24, 2026
wait() helper for DOM-based detectionswaitFor() helper for DOM-based detections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DOM-based detections like
isOrganizationProfile()can fail if called before elements render. This adds an async wrapper to poll detections until they return true or the document completes loading.Implementation
utils.waitFor(detection): Polls detection function viarequestAnimationFrameuntil it returnstrueordocument.readyState === 'complete'Promise<boolean>utilsobject for better organizationUsage
Works with any detection function. Useful for features that initialize before page load completes.
Original prompt
elementReady-like helper for DOM detections #85💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.